<html>
<head><meta charset="utf-8"><title>identity conversion is not inlined · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/identity.20conversion.20is.20not.20inlined.html">identity conversion is not inlined</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="204697469"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/identity%20conversion%20is%20not%20inlined/near/204697469" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joonatan Saarhelo <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/identity.20conversion.20is.20not.20inlined.html#204697469">(Jul 22 2020 at 17:33)</a>:</h4>
<p>I've spent the last two days looking at a case where adding an unnecessary <code>.into()</code> makes the compiler generate more assembly.</p>
<p>I tried putting #[inline(always)] on the <a href="https://doc.rust-lang.org/src/core/convert/mod.rs.html#553-569">two relevant trait impls</a> and it made my code smaller but the case I was looking at earlier still didn't inline.</p>
<p>Today I tried to make a minimal reproduction of it but it is too flaky for that. I am currently at a point where adding a feature flag to Cargo.toml makes it work properly, even if the flag is not used. It also stopped reproducing on stable at some point in the minimization process but continued to work on nightly and my own stage2.</p>
<p>Is this a bug? I thought inline(always) was supposed to force inlining, which should result in no code being generated.</p>



<a name="204697697"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/identity%20conversion%20is%20not%20inlined/near/204697697" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/identity.20conversion.20is.20not.20inlined.html#204697697">(Jul 22 2020 at 17:35)</a>:</h4>
<p><code>always</code> === "try really hard". It doesn't actually mean always, sadly.</p>



<a name="204698038"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/identity%20conversion%20is%20not%20inlined/near/204698038" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/identity.20conversion.20is.20not.20inlined.html#204698038">(Jul 22 2020 at 17:38)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116155">Jake Goulding</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/identity.20conversion.20is.20not.20inlined/near/204697697">said</a>:</p>
<blockquote>
<p><code>always</code> === "try really hard". It doesn't actually mean always, sadly.</p>
</blockquote>
<p><a href="https://github.com/rust-lang/rust/issues/53827">https://github.com/rust-lang/rust/issues/53827</a></p>



<a name="204698355"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/identity%20conversion%20is%20not%20inlined/near/204698355" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joonatan Saarhelo <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/identity.20conversion.20is.20not.20inlined.html#204698355">(Jul 22 2020 at 17:42)</a>:</h4>
<p>ok, that explains it somewhat</p>



<a name="204698529"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/identity%20conversion%20is%20not%20inlined/near/204698529" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joonatan Saarhelo <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/identity.20conversion.20is.20not.20inlined.html#204698529">(Jul 22 2020 at 17:43)</a>:</h4>
<p>But maybe my changes should be merged? At least inlining the trivial case of From is always good. I'm less sure about the Into based on From</p>



<a name="204698665"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/identity%20conversion%20is%20not%20inlined/near/204698665" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/identity.20conversion.20is.20not.20inlined.html#204698665">(Jul 22 2020 at 17:44)</a>:</h4>
<p>I don't see any particular reason not to, so it seems worth opening a PR and getting smarter people than me to look at it.</p>



<a name="204698744"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/identity%20conversion%20is%20not%20inlined/near/204698744" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joonatan Saarhelo <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/identity.20conversion.20is.20not.20inlined.html#204698744">(Jul 22 2020 at 17:45)</a>:</h4>
<p>Ok, will do</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>